<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>$Title$</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

    <h3>表单提交</h3>
    <form action="/test/add" method="get">
        <p>图书名称：<input type="text" name="bookName"></p>
        <p>图书作者：<input type="text" name="bookAuthor"></p>
        <p>图书价格：<input type="text" name="bookPrice"></p>
        <p>出版时间：<input type="text" name="publicTime"></p>
        <p><input type="submit" value="提交"></p>
    </form>

    <h3>超链接提交</h3>
    <a href="book/add1?bookName=java">URL提交</a>

    <h3>AJAX提交</h3>
    <input type="button" value="ajax提交" id="btn1">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        $("#btn1").click(function () {
            var obj = {};
            obj.bookName = "java";
            obj.bookAuthor = "张三";
            obj.bookPrice = 3.33;
            var s = JSON.stringify(obj);
            $.ajax({
                url:"book/update",
                type:"post",
                dataType:"json", //设置预期服务器返回的数据类型为JSON
                //data的值为json格式字符串，contentType必须设置为"application/json"
                contentType:"application/json",
                data:s,
                success:function (res) {
                    console.log(res);
                }
            });
        })
    </script>

</body>
</html>